package com.bugly.log

import com.blankj.utilcode.util.AppUtils
import com.tencent.bugly.crashreport.BuglyLog
import com.bugly.log.enums.LogLevel


object MyLogger {

    private var level = if (AppUtils.isAppDebug())  LogLevel.DEBUG else LogLevel.WARN

    private fun tag(topic: String) = LogConstants.TAG + "#" + topic

    fun info(topic: String, log: String) {
        if (level >= LogLevel.INFO) {
            BuglyLog.i(tag(topic), log)
        }
    }

    fun debug(topic: String, log: String) {
        if (level >= LogLevel.DEBUG) {
            BuglyLog.d(tag(topic),  log)
        }
    }

    fun warn(topic: String, log: String) {
        if (level >= LogLevel.WARN) {
            BuglyLog.w(tag(topic),  log)
        }
    }

    fun error(topic: String, log: String) {
        error(topic, log, null)
    }

    fun error(topic: String, log: String, error: Throwable? = null) {
        if (error == null) {
            BuglyLog.e(tag(topic),  log)
        }else{
            BuglyLog.e(tag(topic), log, error)
        }
    }
}